home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / win / c / 3d_dll.exe / DEMODLG.C < prev    next >
C/C++ Source or Header  |  1991-10-21  |  9KB  |  284 lines

  1. #include <windows.h>
  2. #include <string.h>
  3. #include "ids.h"
  4. #include "demo.h"
  5. #include "three_d.h"
  6.  
  7. BOOL FAR PASCAL DemoDlgProc(HWND,WORD,WORD,LONG);
  8. BOOL FAR PASCAL ComboDlgProc(HWND,WORD,WORD,LONG);
  9. BOOL FAR PASCAL AboutDlgProc(HWND,WORD,WORD,LONG);
  10. static void AdjustPosition(HWND);
  11.  
  12. extern HANDLE hInst;
  13.  
  14. /*
  15.    ****************************************************************************
  16.    DemoDlgProc()
  17.    Handles all messages for the 3-D demo dialog box.
  18.    ****************************************************************************
  19. */
  20.  
  21. BOOL FAR PASCAL DemoDlgProc(HWND hDlg, WORD msg, WORD wParam, LONG lParam)
  22. {
  23.    FARPROC lpprocAboutDlg;
  24.  
  25.    switch (msg)
  26.    {
  27.       case WM_INITDIALOG:
  28.          AdjustPosition(hDlg);
  29.          /* Fill listboxes and combo boxes with current directory listing */
  30.          DlgDirList(hDlg,"*.*",IDD_9,NULL,0x0000);
  31.          DlgDirListComboBox(hDlg,"*.*",IDD_12,NULL,0x0000);
  32.          DlgDirListComboBox(hDlg,"*.*",IDD_13,NULL,0x0000);
  33.          DlgDirListComboBox(hDlg,"*.*",IDD_14,NULL,0x0000);
  34.  
  35.          /* Hide group boxes which will be made three_d */
  36.          ShowWindow(GetDlgItem(hDlg,IDD_6),SW_HIDE);
  37.          ShowWindow(GetDlgItem(hDlg,IDD_7),SW_HIDE);
  38.          break;
  39.  
  40.       case WM_CTLCOLOR:                      /* Allow DLL to handle this one */
  41.          return(Control3dColor(hDlg,wParam));
  42.  
  43.       case WM_PAINT:
  44.          /* This posts a message to the DLL defined message WM_3DPAINT */
  45.          /* It is very important to return FALSE here, to allow the dialog */
  46.          /* handler to process the WM_PAINT message first */
  47.          PostMessage(hDlg,WM_3DPAINT,0,0L);
  48.          return (FALSE);
  49.  
  50.       case WM_3DPAINT:
  51.          /* This code calls functions in the DLL to make the controls in the */
  52.          /* dialog box 3-D */
  53.  
  54.          Draw3dFrame(hDlg,INSIDE_FRAME);
  55.          Draw3dBorder(hDlg,IDD_1,RECESSED,1);
  56.          Draw3dBorder(hDlg,IDD_2,RAISED,1);
  57.  
  58.          Draw3dBorder(hDlg,IDD_3,RECESSED,2);
  59.          Draw3dBorder(hDlg,IDD_4,RAISED,2);
  60.          Draw3dShadow(hDlg,IDD_5);
  61.  
  62.          Draw3dBorder(hDlg,IDD_6,RECESSED,3);
  63.          Draw3dBorder(hDlg,IDD_7,CREASED,3);
  64.          Draw3dShadow(hDlg,IDD_8);
  65.  
  66.          Draw3dBorder(hDlg,IDD_9,RECESSED,1);
  67.          Draw3dBorder(hDlg,IDD_10,RAISED,1);
  68.          Draw3dShadow(hDlg,IDD_11);
  69.  
  70.          Draw3dBorder(hDlg,IDD_12,RECESSED,2);
  71.          Draw3dBorder(hDlg,IDD_13,RAISED,2);
  72.          Draw3dShadow(hDlg,IDD_14);
  73.  
  74.          Draw3dBorder(hDlg,IDD_15,RECESSED,3);
  75.          Draw3dBorder(hDlg,IDD_16,RAISED,3);
  76.          Draw3dShadow(hDlg,IDD_17);
  77.  
  78.          Draw3dBorder(hDlg,IDOK,RECESSED,2);
  79.          Draw3dBorder(hDlg,IDCANCEL,RECESSED,2);
  80.          Draw3dBorder(hDlg,IDD_ABOUT,RECESSED,2);
  81.  
  82.          break;
  83.  
  84.       case WM_COMMAND:
  85.          switch(wParam)
  86.          {
  87.             case IDOK:
  88.             case IDCANCEL:
  89.                EndDialog(hDlg,TRUE);
  90.                break;
  91.  
  92.             case IDD_ABOUT:
  93.                lpprocAboutDlg = MakeProcInstance(AboutDlgProc,hInst);
  94.                DialogBox(hInst,"AboutBox",hDlg,lpprocAboutDlg);
  95.                FreeProcInstance(lpprocAboutDlg);
  96.                break;
  97.  
  98.             default:
  99.                return (FALSE);
  100.          }
  101.          break;
  102.  
  103.       default:
  104.          return(FALSE);
  105.    }
  106.    return (TRUE);
  107. }
  108.  
  109. /*
  110.    ****************************************************************************
  111.    ComboDlgProc()
  112.    Handles all messages for the 3-D combo dialog box.
  113.    ****************************************************************************
  114. */
  115.  
  116. BOOL FAR PASCAL ComboDlgProc(HWND hDlg, WORD msg, WORD wParam, LONG lParam)
  117. {
  118.    LPMEASUREITEMSTRUCT lpmis;
  119.    LPDRAWITEMSTRUCT lpdis;
  120.    HDC hdc;
  121.    static HFONT hFont;
  122.    HFONT hOldFont;
  123.    int nMode;
  124.    DWORD dwOldClr;
  125.  
  126.    switch (msg)
  127.    {
  128.       case WM_INITDIALOG:
  129.          AdjustPosition(hDlg);
  130.          hFont = CreateFont(16,5,0,0,700,0,0,0,ANSI_CHARSET,OUT_DEFAULT_PRECIS,
  131.             CLIP_DEFAULT_PRECIS,PROOF_QUALITY,VARIABLE_PITCH|FF_SWISS,"Helv");
  132.                         
  133.          DlgDirList(hDlg,"*.*",IDD_LIST,NULL,0x0000);
  134.          DlgDirListComboBox(hDlg,"*.*",IDD_COMBO,NULL,0x0000);
  135.          break;
  136.  
  137.       case WM_CTLCOLOR:                      /* Allow DLL to handle this one */
  138.          return(Control3dColor(hDlg,wParam));
  139.  
  140.       case WM_PAINT:
  141.          /* This posts a message to the DLL defined message WM_3DPAINT */
  142.          /* It is very important to return FALSE here, to allow the dialog */
  143.          /* handler to process the WM_PAINT message first */
  144.          hdc = GetDC(hDlg);
  145.          hOldFont=SelectObject(hdc,hFont);
  146.          nMode = SetBkMode(hdc,TRANSPARENT);
  147.          SetTextColor(hdc,GetSysColor(COLOR_BTNSHADOW));
  148.          TextOut(hdc,6,6,(LPSTR)"3-D Ownerdraw list/combo boxes",30);
  149.          dwOldClr = SetTextColor(hdc,RGB(255,255,255));
  150.          TextOut(hdc,5,5,(LPSTR)"3-D Ownerdraw list/combo boxes",30);
  151.          SetBkMode(hdc,nMode);
  152.          SetTextColor(hdc,dwOldClr);
  153.          SelectObject(hdc,hOldFont);
  154.          ReleaseDC(hDlg,hdc);
  155.          PostMessage(hDlg,WM_3DPAINT,0,0L);
  156.          return (FALSE);
  157.  
  158.       case WM_3DPAINT:
  159.          /* This code calls functions in the DLL to make the controls in the */
  160.          /* dialog box 3-D */
  161.          Draw3dFrame(hDlg,OUTSIDE_FRAME);
  162.          Draw3dBorder(hDlg,IDD_COMBO,RECESSED,2);
  163.          Draw3dBorder(hDlg,IDD_LIST,RECESSED,2);
  164.          Draw3dBorder(hDlg,IDOK,RECESSED,2);
  165.          break;
  166.  
  167.       case WM_MEASUREITEM:
  168.          /* Set the height of items in the listbox and combo box */
  169.          lpmis = (LPMEASUREITEMSTRUCT)lParam;
  170.          /* Use vertical dialog base unit + 2 */
  171.          lpmis->itemHeight = HIWORD(GetDialogBaseUnits()) + 2;
  172.          break;
  173.  
  174.       case WM_DRAWITEM:
  175.          /* If there were other owner-draw controls here, you would need a */
  176.          /* switch statement to handle them.  For now, just do the listbox */
  177.          /* and the combo box */
  178.          lpdis = (LPDRAWITEMSTRUCT)lParam;
  179.  
  180.          if (lpdis->itemID == -1)
  181.             Handle3dFocus(lpdis);            /* No items yet, just do focus */
  182.          else
  183.          {
  184.             Draw3dItem(lpdis);               /* Draw entire item selected or not */
  185.             Handle3dFocus(lpdis);            /* Handle focus */
  186.          }
  187.          break;
  188.  
  189.       case WM_COMMAND:
  190.          switch(wParam)
  191.          {
  192.             case IDOK:
  193.             case IDCANCEL:
  194.                EndDialog(hDlg,TRUE);
  195.                break;
  196.  
  197.             default:
  198.                return (FALSE);
  199.          }
  200.          break;
  201.  
  202.       case WM_DESTROY:
  203.          DeleteObject(hFont);
  204.          break;
  205.  
  206.       default:
  207.          return(FALSE);
  208.    }
  209.    return (TRUE);
  210. }
  211.  
  212. BOOL FAR PASCAL AboutDlgProc(HWND hDlg, WORD msg, WORD wParam, LONG lParam)
  213. {
  214.    switch (msg)
  215.    {
  216.       case WM_INITDIALOG:
  217.          AdjustPosition(hDlg);
  218.          break;
  219.  
  220.       case WM_CTLCOLOR:
  221.          return(Control3dColor(hDlg,wParam));
  222.  
  223.       case WM_PAINT:
  224.          PostMessage(hDlg,WM_3DPAINT,0,0L);
  225.          return (FALSE);
  226.  
  227.       case WM_3DPAINT:
  228.          Draw3dFrame(hDlg,OUTSIDE_FRAME);
  229.          Draw3dBorder(hDlg,IDD_ICON1,RAISED,2);
  230.          Draw3dBorder(hDlg,IDD_HEADER,RECESSED,2);
  231.          Draw3dBorder(hDlg,IDD_ICON2,RAISED,2);
  232.          Draw3dShadow(hDlg,IDD_RECT);
  233.          break;
  234.  
  235.       case WM_COMMAND:
  236.          switch(wParam)
  237.          {
  238.             case IDOK:
  239.                EndDialog(hDlg,TRUE);
  240.                break;
  241.  
  242.             default:
  243.                return (FALSE);
  244.          }
  245.          break;
  246.  
  247.       default:
  248.          return(FALSE);
  249.    }
  250.    return (TRUE);
  251. }
  252.  
  253. /*
  254.    ****************************************************************************
  255.    AdjustPosition()
  256.    Adjusts the position of the passed window so that it is centered both
  257.    horizontally and vertically in the client of the main window.
  258.    ****************************************************************************
  259. */
  260.  
  261. void AdjustPosition(hWindow)
  262. HWND hWindow;
  263. {
  264.    RECT hRect;
  265.    short xSize,ySize,xPos,yPos;
  266.    sho